var headImg = $('.headImg').attr('src');
if(headImg == ''){
	$('.headImg').attr('src',$('.headImg').attr('data-src'));
}else{
	//不做任何处理
}

function initVal(){
	var address = $('input[name=address]').val();
	if(Boolean(address)){
		$('.countryChoose').html(address);
	}else{
		$('.countryChoose').html('省市区');
	}
	
}
initVal();

/*----------------省市区----------------*/
var provinceId,cityId,areaStrId;
$('.mui-navigate-right').on('click',function(){
	$('.mui-content').hide();
	$('.footer').hide();
	$('.header').hide();
	$('#distpicker3').show();
})
$("#distpicker3").distpicker({
  province: "浙江省",
  city: "杭州市",
  district: "西湖区"
});
/*$('.span1').on('click',function(){
	$('.span2').show();
	$('.span1').hide();
	$('#select2').show();
	$('#select1').hide();
})*/
/*$('.span2').on('click',function(){
	$('.span3').show();
	$('.span2').hide();
	$('#select3').show();
	$('#select2').hide();
})*/
$('.addressSubmit').on('click',function(){
	/*$('.span3').hide();
	$('.span1').show();*/
	/*$('#select3').hide();
	$('#select1').show();*/
	$('#distpicker3').hide();
	$('.mui-content').show();
	$('.footer').show();
	$('.header').show();
	var province = $('#select1 option:checked').val();
	var city = $('#select2 option:checked').val();
	var areaStr = $('#select3 option:checked').val();
	provinceId = $('#select1 option:checked').attr('data-code');
	cityId = $('#select2 option:checked').attr('data-code');
	areaStrId = $('#select3 option:checked').attr('data-code');
	$('.countryChoose').html(province+" "+city+" "+areaStr);
})
var province = $('#select1 option:checked').val();
var city = $('#select2 option:checked').val();
var areaStr = $('#select3 option:checked').val();
provinceId = $('#select1 option:checked').attr('data-code');
cityId = $('#select2 option:checked').attr('data-code');
areaStrId = $('#select3 option:checked').attr('data-code');
/*-------------------------保存----------------------------*/
var addressF = $('.countryChoose').val();
$('.saveIcon').on('click',function(){
	$('.levelPriceTip').show();
	$('.saveTip').show();
	$('.saveTipContent').html('确认保存吗？')
})
$('.saveTipCancel').on('click',function(){
	$('.levelPriceTip').hide();
	$('.saveTip').hide();
})
$('.saveTipSubmit').on('click',function(){
	var addressS = $('.countryChoose').val();
	if(addressF != addressS){
		$('input[name=addressInfo]').val(addressS);
	}
	$('input[name=provinceId]').val(provinceId);
	$('input[name=cityId]').val(cityId);
	$('input[name=areaId]').val(areaStrId);
	if(Boolean($('.countryChoose').html())){
		$('.personForm').submit();
	}else{
		tip('请将地址填写完整');
	}
})
/*-----------------------供应商主动修改分销商级别---------------------------*/
$('.level').on('change',function(){
	$('.levelPriceTip').show();
	$('.selectTip').show();
	$('.saveTipContent').html('是否确认修改级别？')
})
$('.selectTipCancel').on('click',function(){
	var firstLevel = $('.firstLevel').html();
	$('.firstLevel').html(firstLevel);
	$('.levelPriceTip').hide();
	$('.selectTip').hide();
})
$('.selectTipSubmit').on('click',function(){
	var level = $('.level option:checked').attr('level');
	var userId = $('input[name=userId]').val();
	$.ajax({
		type:"POST",
		url : "/weishang/distributor/modifyUserLevel.json",
		dataType : "json",
		data : {
			"level" :level,
			"userId":userId
		},
		success : function(data) {
			console.log(data);
		 if(data["code"] == "200") {	
			 window.location.href="/weishang/distributor/distributorDetail.htm?userId="+userId;
			}else if(data["code"] == "-200") {
				$('.levelPriceTip').hide();
				$('.selectTip').hide();
				mui.toast('修改失败');
			}
		}
	})
	
	
})
//充值
$('.recharge').on('click',function(){
	$('.rechargeTip').show();
	$('.mui-active').show();
})
$('.rechargeTipCancel').on('click',function(){
	$('.rechargeTip').hide();
	$('.mui-active').hide();
})
$('.rechargeTipSubmit').on('click',function(){
	$('.rechargeTip').hide();
	$('.mui-active').hide();
	var level = $('.level').val();
	window.location.href="/weishang/distributor/doRecharge.htm?level="+level+"&type=1";
})
//友情提示弹框
function tip(error){
	$('#errorInfo').html(error);
	$('.mui-active').show();
	$('#errorTip').show();
}
//友情提示确认
$('.queren').on('click',function(){
	$('.mui-active').hide();
	$('#errorTip').hide();
})

//禁止获取焦点
$(document).find($('input').attr('readOnly')).on('click',function(){
	$(this).blur();
})